package springboot.listenConsumer;

/*注意Channel的包一定是这个包*/
import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import springboot.bean.User;
import springboot.config.RabbitMQConfig;

import java.io.UnsupportedEncodingException;
import java.util.Date;

@Slf4j
@Component
public class DeadLetterQueueConsumer {

    @RabbitListener(queues ={RabbitMQConfig.QUEUE_D})
    public void receiveQD(Message message, Channel channel) throws UnsupportedEncodingException {
        String msg=new String(message.getBody(),"UTF-8");
        User user=JSON.parseObject(msg, User.class);
        log.info("当前时间{},收到消息{}",new Date(),user.toString());
    }
}
